package pkg4funlex;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author 4FunTeam
 */
public class Reserved {
    public static HashMap<String, String> Words;

    public static boolean contains(String word) {
        return Words.containsKey(word);
    }

    public static String type(String word) {
        return Words.get(word);
    }

    public static void init(String wordFilePath) {
        Words = new HashMap<String, String>();
        BufferedReader wordFile = null;
        try {
            wordFile = new BufferedReader(new FileReader(wordFilePath));
        } catch (FileNotFoundException ex) {
            System.out.println("NAO CONSEGUIU ABRIR FILE! " + ex);
        }

        try {
            String line;
            String[] words = new String[2];
            while( (line = wordFile.readLine()) != null) {
                if(line != null) {
                    words = line.split(" ");
                    Words.put(words[0], words[1]);
                }
            }
        } catch (Exception ex) {
            System.out.println("Erro: " + ex);
        } finally {
            try {
                wordFile.close();
            } catch (Exception ex) {
                System.out.println("Erro ao fechar arquivo" + wordFilePath + ": " + ex);
            }
        }
    }
}
